//
//  SGResourceModel.swift
//  songguo
//
//  Created by 潘传洲 on 16/6/11.
//  Copyright © 2016年 pcz. All rights reserved.
//

import UIKit

enum ResourceType : Int{
    case Picture = 0
    case Video = 1
    case Text = 2
}

class SGResourceModel: NSObject {
    
    var tp : ResourceType? // 0 图片 1 视频 2文字
    var txt : String?
    var url : String?
    var poster : String? // 视频封面
    var duration : Double? // 视频时长
    var width : CGFloat?
    var height : CGFloat?
    var isSubTitle : Bool = false
    
    
    class func resourceModels(array : [[String : AnyObject]]) -> [SGResourceModel] {
        var resourceModels = [SGResourceModel]()
        for dict in array {
            let resourceModel = SGResourceModel()
            resourceModel.tp = ResourceType.init(rawValue: (dict["tp"] as? Int)!)
            switch resourceModel.tp! {
                
            case .Picture:// 0 图片
                resourceModel.url = dict["url"] as? String
                resourceModel.width = dict["width"] as? CGFloat
                resourceModel.height = dict["height"] as? CGFloat
                
            case .Video://1 视频
                resourceModel.url = dict["url"] as? String
                resourceModel.poster = dict["poster"] as? String
                resourceModel.duration = dict["duration"] as? Double
                resourceModel.width = dict["width"] as? CGFloat
                resourceModel.height = dict["height"] as? CGFloat
                
            case .Text://2文字
                resourceModel.txt = dict["txt"] as? String
                resourceModel.isSubTitle = (dict["isSubTitle"] as? Int) == 1 ? true : false
            }
            
            resourceModels.append(resourceModel)
        }
        return resourceModels
    }
    
}
